package dao;

import java.sql.SQLException;

public class SuperLoginDAO extends BaseDAO{
	
	public boolean superLogin(String superPass){
		boolean flag=false;
		String sql="select * from tb_super where super_pass=?";
			try {
				conn=getConnection();
				ps=conn.prepareStatement(sql);
				ps.setString(1, superPass);
				rs=ps.executeQuery();
				if(rs.next()){
					flag=true;
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}finally{
		        closeSource(conn, ps, rs);
			}
		return flag;
	}
	public int getPowerNum(){
		int num=0;
		String sql="select count(*) as num from tb_super";
		try {
			conn=getConnection();
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()){
				num=rs.getInt("num");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			closeSource(conn, ps, rs);
		}
		return num;
	}
	public boolean addPowerCode(){
		boolean flag=false;
		int aa=0;
		int bb=0;
		String sql="insert into tb_power values(?,?)";
		try {
			conn=getConnection();
			ps=conn.prepareStatement(sql);
			for(int i=0;i<20;i++){
				aa=(int) (1000*Math.random());
				bb=(int) (1000*Math.random());
				ps.setString(1, ""+aa);
				ps.setString(2, ""+bb);
				ps.executeUpdate();
			}
			flag=true;
		}catch (SQLException e1) {
			e1.printStackTrace();
		}finally{
			closeSource(conn, ps, rs);
		}
		return flag;
	}
}
